﻿using System.Text;
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Data.Linq;
using System.Linq;
using mmoss.orm;

/// <summary>
/// Summary description for PageBase
/// </summary>
/// 
namespace mmoss.web
{
    public class PageBase : System.Web.UI.Page
    {


        protected void NotifyEndUser(bool isError
            , string message)
        {
            //---TODO: if error should log
            StringBuilder sbMessage = new StringBuilder();
            sbMessage.Append("function AlertMe(msg)");
            sbMessage.Append("\r\n");
            sbMessage.Append("{");
            sbMessage.Append("\t");
            sbMessage.AppendFormat("alert(\"{0}\");", message);
            sbMessage.Append("\r\n");
            sbMessage.Append("}");

            if (!Page.ClientScript.IsStartupScriptRegistered("AlertScript"))
            {
                Page.ClientScript.RegisterStartupScript(typeof(string), "AlertScript", sbMessage.ToString(), true);
            }
        }

        public User LoginUser
        {
            get
            {
                //---TODO: should we try to retrieve from view state?
                return Session["loggedinUser"] as User;
            }
            set
            {
                Session["loggedinUser"] = value;
            }
        }


        protected virtual void Page_Load(object sender, EventArgs e)
        {
            //check page authentication
            /*
            if (this.RexUser == null && !this.IsLoginPage)
            {
                Session[SessionKeys.REQUESTEDURL] = Page.Request.Url;
                Response.Redirect("~/Public/LogOn.aspx");
                return;
            }
            */

        }


        public PageBase()
        {
            MaintainScrollPositionOnPostBack = true;
        }

    }
}